import { createRouter, createWebHashHistory } from 'vue-router'
// Layout不做懒加载，因为每一个组件都会用到（除了登录以外的小页面 ）
import Layout from '@/views/layout/index.vue'
import Home from '@/views/home/index.vue'

// https://router.vuejs.org/guide/#javascript
const router = createRouter({
  history: createWebHashHistory(),
  // Vue-Router 滚动行为
  scrollBehavior(to, from, savedPosition) {
    // 始终滚动到顶部
    return { top: 0 }
  },
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          // home
          path: '',
          component: Home
        },
        {
          // 顶部一级
          path: '/category/:id',
          component: () => import('@/views/category/index.vue')
        },
        {
          // 顶部二级
          path: '/category/sub/:id',
          component: () => import('@/views/category/sub.vue')
        },
        // 商品详情
        {
          path: '/goods/:id',
          component: () => import('@/views/goods/index.vue')
        }
      ]
    },
    { path: '/login', component: () => import('@/views/login/index.vue') },
    { path: '/playground', component: () => import('@/views/playground/index.vue') }
  ]
})

export default router